import HttpRequest from '@/plugins/axios'
import { authentication } from '@/utils/authentication'
const baseUrl = import.meta.env.VITE_BASE_URL

const api = new HttpRequest(baseUrl)

export const get = (url, params = {}, contentType = '') => {
  return new Promise((resolve, reject) => {
    api
      .get(url, params, contentType)
      .then((res) => {
        authentication(res)
        resolve(res)
      })
      .catch((error) => {
        reject(error)
      })
  })
}
export const post = (url, params = {}, contentType = '', otherParams = {}) => {
  return new Promise((resolve, reject) => {
    api
      .post(url, params, contentType, otherParams)
      .then((res) => {
        authentication(res)
        resolve(res)
      })
      .catch((error) => {
        reject(error)
      })
  })
}

export const qsPost = (url, params = {}, contentType = '') => {
  return new Promise((resolve, reject) => {
    api
      .qsPost(url, params, contentType)
      .then((res) => {
        authentication(res)
        resolve(res)
      })
      .catch((error) => {
        reject(error)
      })
  })
}

export const qsPut = (url, params = {}, contentType = '') => {
  return new Promise((resolve, reject) => {
    api
      .qsPut(url, params, contentType)
      .then((res) => {
        authentication(res)
        resolve(res)
      })
      .catch((error) => {
        reject(error)
      })
  })
}

export const put = (url, params = {}, contentType = '', otherParams = {}) => {
  return new Promise((resolve, reject) => {
    api
      .put(url, params, contentType, otherParams)
      .then((res) => {
        authentication(res)
        resolve(res)
      })
      .catch((error) => {
        reject(error)
      })
  })
}

export const deleteData = (url, params = {}, contentType = '') => {
  return new Promise((resolve, reject) => {
    api
      .deleteData(url, params, contentType)
      .then((res) => {
        authentication(res)
        resolve(res)
      })
      .catch((error) => {
        reject(error)
      })
  })
}
